import {createApp} from 'vue';
// global css
import 'uno.css';
import '@/assets/styles/index.scss';
import 'element-plus/theme-chalk/dark/css-vars.css';

// App、router、store
import App from './App.vue';
import {store} from './store';
import router, {setupRouter} from './router';

import {setupStore} from '@/store';
import {setupI18n} from '@/locales/setupI18n';
// 自定义指令
import directive from './directive';

// 注册插件
import plugins from './plugins/index'; // plugins
import {download} from '@/utils/request';

// 预设动画
// import animate from './animate';

// svg图标
import 'virtual:svg-icons-register';
import ElementIcons from '@/plugins/svgicon';

// permission control
import './permission';

import {useDict} from '@/utils/dict';
import {getConfigKey, updateConfigByKey} from '@/api/system/config';
import {parseTime, addDateRange, handleTree, selectDictLabel, selectDictLabels} from '@/utils/helper';
import mitt from '@/utils/mitt';

const emitter = mitt();


//声明文件 不然TS无法正确类型 推导
declare module 'vue' {
    // 声明要扩充@vue/runtime-core包的声明.
    // 这里扩充"ComponentCustomProperties"接口, 因为他是vue3中实例的属性的类型.
    export interface ComponentCustomProperties {
        $useDict: any;
    }
}

import {isDevMode} from './utils/env';

if (isDevMode()) {
    import('ant-design-vue/es/style');
}

async function bootstrap() {
    const app = createApp(App);
// 全局方法挂载
    app.config.globalProperties.useDict = useDict;
    app.config.globalProperties.getConfigKey = getConfigKey;
    app.config.globalProperties.updateConfigByKey = updateConfigByKey;
    app.config.globalProperties.download = download;
    app.config.globalProperties.parseTime = parseTime;
    app.config.globalProperties.handleTree = handleTree;
    app.config.globalProperties.addDateRange = addDateRange;
    app.config.globalProperties.selectDictLabel = selectDictLabel;
    app.config.globalProperties.selectDictLabels = selectDictLabels;
    // app.config.globalProperties.animate = animate;
    // Initialize internal system configuration
    // 初始化内部系统配置

    // Register global components
    // 注册全局组件

    // Multilingual configuration
    // 多语言配置
    // Asynchronous case: language files may be obtained from the server side
    // 异步案例：语言文件可能从服务器端获取
    await setupI18n(app);
    app.provide('emitter', emitter); // 注入provider

    setupRouter(app);
    // Configure store
    // 配置 store
    setupStore(app);

    app.use(ElementIcons);

    app.use(plugins);
// 自定义指令
    directive(app);


    // Configure routing
    // 配置路由

    // router-guard
    // 路由守卫

    // Register global directive
    // 注册全局指令

    // Configure global error handling
    // 配置全局错误处理

    // https://next.router.vuejs.org/api/#isready
    // await router.isReady();

    app.mount('#app');
}

bootstrap();


